<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoLog class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.miscellaneous.html">Miscellaneous</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongolog.getcallback.html">MongoLog::getCallback</a></div>
 <div class="up"><a href="mongo.miscellaneous.html">Miscellaneous</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.mongolog" class="reference">

 <h1 class="title">The MongoLog class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL mongo &gt;=1.2.3)</p>


  <div class="section" id="mongolog.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    Logging can be used to get detailed information about what the driver is
    doing. The logging mechanism as used by MongoLog emits all log messages
    as a PHP notice. Depending on the server interface that you use,
    that means that they will either be sent to strerr (with PHP-CLI), or
    otherwise to the web server&#039;s error log. In order for log messages to
    be output by PHP their level (E_NOTICE) does need to be configured to
    be shown. That means the E_NOTICE bit needs to be part of PHP&#039;s
    error_reporting level and that display_errors is set to 1.
   </p>
   <p class="para">
    Logging is turned off, by default. This class allows you to turn on
    specific levels of logging for specific parts of the driver. Some examples:
   </p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;print&nbsp;every&nbsp;log&nbsp;message&nbsp;possible<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setLevel</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">ALL</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;all&nbsp;log&nbsp;levels<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setModule</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">ALL</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;all&nbsp;parts&nbsp;of&nbsp;the&nbsp;driver<br /><br />//&nbsp;print&nbsp;significant&nbsp;events&nbsp;about&nbsp;replica&nbsp;set&nbsp;failover<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setLevel</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">INFO</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setModule</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">RS</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;print&nbsp;info-&nbsp;and&nbsp;server&nbsp;tuning-level&nbsp;events&nbsp;from&nbsp;replica&nbsp;sets&nbsp;and&nbsp;connection&nbsp;pooling<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setLevel</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">INFO</span><span style="color: #007700">|</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">FINE</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">setModule</span><span style="color: #007700">(</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">RS</span><span style="color: #007700">|</span><span style="color: #0000BB">MongoLog</span><span style="color: #007700">::</span><span style="color: #0000BB">POOL</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>


  <div class="section" id="mongolog.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">MongoLog</strong>
     </span>
     {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 常量 */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.none"><var class="varname">NONE</var></a></var>
     <span class="initializer"> = 0</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.all"><var class="varname">ALL</var></a></var>
     <span class="initializer"> = 31</span>
    ;</div>


    <div class="classsynopsisinfo">level constants {</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.warning"><var class="varname">WARNING</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.info"><var class="varname">INFO</var></a></var>
     <span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.fine"><var class="varname">FINE</var></a></var>
     <span class="initializer"> = 4</span>
    ;</div>


    <div class="classsynopsisinfo">module constants {</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.rs"><var class="varname">RS</var></a></var>
     <span class="initializer"> = 1</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.pool"><var class="varname">POOL</var></a></var>
     <span class="initializer"> = 2</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.io"><var class="varname">IO</var></a></var>
     <span class="initializer"> = 4</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.server"><var class="varname">SERVER</var></a></var>
     <span class="initializer"> = 8</span>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.mongolog.html#mongolog.constants.parse"><var class="varname">PARSE</var></a></var>
     <span class="initializer"> = 16</span>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Fields */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier"/>
     <span class="type">int</span>
      <var class="varname">$<var class="varname">level</var></var>
    ;</div>

    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="type">int</span>
      <var class="varname">$<var class="varname">module</var></var>
    ;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">void</span><span class="methodname"><a href="mongolog.getcallback.html" class="methodname">getCallback</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">int</span><span class="methodname"><a href="mongolog.getlevel.html" class="methodname">getLevel</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">int</span><span class="methodname"><a href="mongolog.getmodule.html" class="methodname">getModule</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">void</span><span class="methodname"><a href="mongolog.setcallback.html" class="methodname">setCallback</a></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$log_function</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">void</span><span class="methodname"><a href="mongolog.setlevel.html" class="methodname">setLevel</a></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$level</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">void</span><span class="methodname"><a href="mongolog.setmodule.html" class="methodname">setModule</a></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$module</code></span>
   )</div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">预定义常量</h2>
   <div class="section" id="mongolog.constants.types">
    <h2 class="title">MongoLog Constants</h2>
    <p class="para">
     These constants can be used by both
     <span class="function"><a href="mongolog.setlevel.html" class="function">MongoLog::setLevel()</a></span> and
     <span class="function"><a href="mongolog.setmodule.html" class="function">MongoLog::setModule()</a></span>.
    </p>

    <dl>

     
      <dt id="mongolog.constants.none"><strong><code>MongoLog::NONE</code></strong></dt>

      <dd>

       <span class="simpara">
        Constant for turning logging off.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.all"><strong><code>MongoLog::ALL</code></strong></dt>

      <dd>

       <span class="simpara">
        Constant for logging everything.
       </span>
      </dd>

     
    </dl>

   </div>

   <div class="section" id="mongolog.constants.level">
    <h2 class="title">MongoLog Level Constants</h2>
    <p class="para">
     These constants can be used by <span class="function"><a href="mongolog.setlevel.html" class="function">MongoLog::setLevel()</a></span>.
    </p>
    <dl>

     
      <dt id="mongolog.constants.warning"><strong><code>MongoLog::WARNING</code></strong></dt>

      <dd>

       <span class="simpara">
        This will print log messages about somewhat exceptional but
        not-quite-exception-worthy happenings.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.info"><strong><code>MongoLog::INFO</code></strong></dt>

      <dd>

       <span class="simpara">
        Logs events that may be of interest to administrators, but are not
        particularly noteworthy.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.fine"><strong><code>MongoLog::FINE</code></strong></dt>

      <dd>

       <span class="simpara">
        Logs most events that the driver performs. Depending on the module being
        logged, this can be extremely noisy and is primarily for debugging.
       </span>
      </dd>

     
    </dl>

   </div>

   <div class="section" id="mongolog.constants.module">
    <h2 class="title">MongoLog Module Constants</h2>
    <p class="para">
     These constants can be used by <span class="function"><a href="mongolog.setmodule.html" class="function">MongoLog::setModule()</a></span>.
    </p>
    <dl>

     
      <dt id="mongolog.constants.io"><strong><code>MongoLog::IO</code></strong></dt>

      <dd>

       <span class="simpara">
        Logs traffic to/from the database. Unless your program is trivial, this
        will create an enormous number of log messages.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.parse"><strong><code>MongoLog::PARSE</code></strong></dt>

      <dd>

       <span class="simpara">
        Log server string parsing.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.pool"><strong><code>MongoLog::POOL</code></strong></dt>

      <dd>

       <span class="simpara">
        Log connection pool activity. Creating new connections, reusing
        connections, and closing connections.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.rs"><strong><code>MongoLog::RS</code></strong></dt>

      <dd>

       <span class="simpara">
        Log replica set activity. Failovers, pinging, chosing secondaries to
        read from, etc.
       </span>
      </dd>

     
     
      <dt id="mongolog.constants.server"><strong><code>MongoLog::SERVER</code></strong></dt>

      <dd>

       <span class="simpara">
        Log server status changes. Detecting primary, secondary and
        duplication detection.
       </span>
      </dd>

     
    </dl>

   </div>
  </div>

 </div>

 











































<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongolog.getcallback.html">MongoLog::getCallback</a> — Retrieve the previously set callback function name</li><li><a href="mongolog.getlevel.html">MongoLog::getLevel</a> — Gets the log level</li><li><a href="mongolog.getmodule.html">MongoLog::getModule</a> — Gets the modules currently being logged</li><li><a href="mongolog.setcallback.html">MongoLog::setCallback</a> — Set a callback function to be called on events</li><li><a href="mongolog.setlevel.html">MongoLog::setLevel</a> — Sets logging level</li><li><a href="mongolog.setmodule.html">MongoLog::setModule</a> — Sets driver functionality to log</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.miscellaneous.html">Miscellaneous</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongolog.getcallback.html">MongoLog::getCallback</a></div>
 <div class="up"><a href="mongo.miscellaneous.html">Miscellaneous</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
